<template>
	<!-- <canvas canvas-id="myCanvas" style="width: 600rpx; height: 600rpx"></canvas>
	 <button @click="screenShotPage">截图</button> -->
	<view class="contain" id="screenShot">
		<view class="row">A.填写个人信息</view>
		<view class="forminfo">
			<view class="input">
				<view class="fieldname">学生姓名</view>
				<view class="fieldvalue"><u-input border="surround" placeholder="必填" v-model="pinfo.data.studentName" :customStyle="customstyle"></u-input></view>
			</view>
			<view class="input">
				<view class="fieldname" style="border-left:0px;">性别</view>
				<view class="fieldvalue" @click="sexshow=true" ><u-input border="surround" v-model="pinfo.data.studentSex" placeholder="必填" disabled :customStyle="customstyle120"></u-input></view>
			</view>
			<view class="input">
				<view class="fieldname" style="border-left:0px;">班级</view>
				<view class="fieldvalue"><u-input border="surround" placeholder="必填" v-model="pinfo.data.className" :customStyle="customstyle200"></u-input></view>
			</view>
		</view>
		<view class="forminfo">
			<view class="input">
				<view class="fieldname">老师姓名</view>
				<view class="fieldvalue"><u-input border="surround" placeholder="必填" v-model="pinfo.data.teacherName" :customStyle="customstyle200"></u-input></view>
			</view>
			<view class="input">
				<view class="fieldname" style="border-left:0px;">老师手机</view>
				<view class="fieldvalue"><u-input type="number" border="surround" placeholder="输入" v-model="pinfo.data.teacherPhone" :customStyle="customstyle200"></u-input></view>
			</view>
		</view>	
		<view class="forminfo">
			<view class="input">
				<view class="fieldname">家长手机</view>
				<view class="fieldvalue"><u-input type="number" border="surround" placeholder="必填" v-model="pinfo.data.jiaZhangPhone" :customStyle="customstyle200"></u-input></view>
			</view>
			<view class="input">
				<view class="fieldname" style="border-left:0px;">学生手机</view>
				<view class="fieldvalue"><u-input type="number" border="surround" placeholder="输入" v-model="pinfo.data.studentPhone" :customStyle="customstyle200"></u-input></view>
			</view>
		</view>
		
		
		<view class="readxieyi">
			<view class="ra">
				 <u-checkbox shape="circle" :checked="xieyiChecked" iconSize="18" size="22" @change="checkselected"></u-checkbox>
			</view>
			<view class="rb" @click="goxieyi">我已阅读并同意《服务协议》及《隐私政策》</view>
		</view>		
		
		<view class="row" style="border-top:0px;">B.面谈筛查一键征询</view>
		<view class="desc">
			<view class="descRow"><text><text class="blod">面谈筛查地点：</text>广东医科大学附属医院体检中心</text></view>
			<view class="descRow"><text><text class="blod">面谈筛查目的：</text>心理量表普查只是代表学生填写的量表分数存在异常，提示学生可能会存在心理困惑或情绪障碍。通过和心理医生面谈更明确排除学生是否存在心理问题以及可能存在哪方面的心理问题。面谈筛查结果会在面谈结束后告知家长并提供是否需要进行心理干预的意见。</text></view>
			<view class="descRow"><text><text class="blod">保密原则：</text>凡是能接触到来访者的个人资料和会谈信息的医师及工作人员，都必须严格遵守保密原则和遵守专业伦理规范。</text></view>
			<view class="descRow"><text><text class="blod">实施质量保障：</text>心理健康面谈筛查由广东医科大学附属医院精神心理科医师实施，参与筛查的学生不需要挂号，家长按照预约的时间陪同学生免费到体检中心进行心理健康一对一面谈筛查。每次面谈时间20至30分钟。</text></view>
		</view>
		<view class="row" style="border-top:0px;">C.选择问题</view>
		<view class="problem" v-for="(item,mainIndex) in problemList">
			<view class="ptitle blod">{{item.title}}</view>
			<view class="potions">
				<text v-for="(subitem,index) in item.asks" 
				:class="(item.asks[index].s===true)?'selectedText':''" 
				@click="selectASK(item.title,mainIndex,index)">{{subitem.t}}</text>
			</view>
		</view>
		<view class="row" style="border-top:0px;">D.预约时间</view>
		<view class="flex justify-center flex-col w-[90%] m-auto result">
			<!-- <u-button v-if="pinfo.data.appointmenttime===''" type="primary" shape="circle" @click="choicetime">选择预约到院时间</u-button> -->
			<!-- <text v-else="pinfo.data.appointmenttime!=''" @click="choicetime">预约时间: {{pinfo.data.appointmenttime}}</text> -->
			<text class="w-[100%] text-center mb-2" v-if="pinfo.data.appointmentthospital!=''" @click="goselect">{{pinfo.data.appointmentthospital}}<text class="small ml-2">(重新选择)</text></text>
			<u-button v-if="pinfo.data.appointmenttime===''" type="primary" shape="circle" :customStyle="{'width':'300rpx'}" @click="goselect">选择预约到院时间</u-button>
			<text class="w-[100%] text-center mt-2" v-else="pinfo.data.appointmenttime!=''" @click="goselect">{{pinfo.data.appointmenttime}}</text>
		</view>
		
		
		<!-- 时间组件 -->
		<u-datetime-picker
			:show="show"
			v-model="value1"
			:minDate="new Date().getTime()"
			mode="datetime" :closeOnClickOverlay="true" 
			@close="closePicker" 
			@confirm="confirmPicker"
			@cancel="cancelPicker">
		</u-datetime-picker>
		
		
		<view class="row" style="border-top:0px;">E.家长与学生签名</view>
		<!-- 签名 -->
		<view class="flex justify-between w-[90%] m-auto SignName">
			<!-- 家长签名 -->
			<view class="left">
				<view class="mt-5" v-if='JiaZhangSignImage' style='text-align: right;'>
					<image :src='JiaZhangSignImage' style='width:200rpx;height:100rpx;'></image>
				</view>
				<view style='text-align: center;font-size: 26rpx;width:200rpx;height:70rpx;line-height: 70rpx;background-color: #0599D7;color:#FFFFFF;border-radius: 40rpx;margin:0 auto;margin-top:50rpx;' @click="showSign('jiazhang')">{{JiaZhangSignImage?'重新签名':'家长签名'}}</view>
			</view>
			<!-- 学生签名 -->
			<view class="right">
				<view class="mt-5" v-if='StudentSignImage' style='text-align: right;'>
					<image :src='StudentSignImage' style='width:200rpx;height:100rpx;'></image>
				</view>
				<view style='text-align: center;font-size: 26rpx;width:200rpx;height:70rpx;line-height: 70rpx;background-color: #0599D7;color:#FFFFFF;border-radius: 40rpx;margin:0 auto;margin-top:50rpx;' @click="showSign('student')">{{StudentSignImage?'重新签名':'学生签名'}}</view>	
			</view>
		</view>
		
		<myPopup ref="pop">
		    <view style='background-color: #FFFFFF;border-top-left-radius: 20rpx;border-top-right-radius: 20rpx;'>
				<view style='margin-left:92%;margin-bottom:10rpx;width:40rpx;height:40rpx;font-size: 26rpx;line-height: 40rpx;background-color: #000000;opacity: 0.5;border-radius: 20rpx;text-align: center;position:fixed;bottom:34.5%;z-index:3000;left:0rpx;color:#FFFFFF' @click='hideShow'>X</view>
				<view style='width:100%;height:100rpx;line-height: 100rpx;font-size: 30rpx;font-weight: bold;text-align: center;' class="mt-3">开始签名</view>
			   <canvas class='firstCanvas' canvas-id="firstCanvas" @touchmove='move' @touchstart='start($event)' @touchend='end'
		        @touchcancel='cancel' @longtap='tap' disable-scroll='true' @error='error'>
		       </canvas>
		       
		       <view class="caozuo">
		       	<view class="chongqian" @tap='clearClick'>
		       		重签
		       	</view>
		       	<view class="over" @click="overSign">
		       		完成签名
		       	</view>
		       </view>
		    </view>
		</myPopup>
		
		
		<view class="savedata">
			<u-button type="primary" @click="saveData" :customStyle="{'height':'100rpx','fontSize':'36rpx'}">保存提交</u-button>
		</view>
		
		
		<!-- <view @click="aaa">
			123123
		</view> -->
		
		 <!-- 这里是页面的其他内容 -->
		    <!-- <canvas canvas-id="myCanvas" style="width: 360px; height: 300px;"></canvas>
		    <button @click="takeScreenshot">截图</button>
		 -->
		 <!-- <canvas canvas-id="canvas" style="width: 100%; height: 100%"></canvas>
		 <button @click="exportImage">保存截屏</button> -->
		 
		<!-- <canvas canvas-id="myCanvas" style="width: 300px; height: 200px;"></canvas>
		<button @click="saveCanvas">保存截屏</button> -->
		
		
		<u-action-sheet 
		:actions="sexlist" 
		:closeOnClickOverlay="true" 
		:closeOnClickAction="true"  
		:show="sexshow"
		@select="selectSex"
		@close="closeSex"
		></u-action-sheet>
		
	</view>
</template>

<script setup lang='ts'>
import { ref,reactive,onMounted,getCurrentInstance } from 'vue'
import {  onLoad,onShow} from '@dcloudio/uni-app'
import myPopup from '@/components/qianxiao-pop/qianxiao-pop.vue'
import {Date_EE,ChineseDate} from '@/common/date.js'
import { userStore } from '@/stores/userStore'
let store = userStore();	
let { hasLogin,userData } = userStore();

let xieyiChecked=ref(false);
let checked=ref(false);

let sexshow=ref(false);
let sexlist=reactive([
	{name:'男'},
	{name:'女'},
]);

const selectSex=(e:any)=>{
	console.log("性别:",e);
	pinfo.data.studentSex=e.name;
	userData.pinfo.studentSex=e.name;
}
const closeSex=()=>{
	sexshow.value=false;
}





var content =ref();
var touchs = [];
var canvasw = 0;
var canvash = 0;
var _that:any=null;

let res=reactive({});

const pop = ref();

let show=ref(false);
let value1=ref('');
const closePicker=()=>{
	show.value=false;
}

const checkselected=()=>{
	xieyiChecked.value=!xieyiChecked.value;
	console.log("xieyiChecked.value",xieyiChecked.value);
}

const goxieyi=()=>{
	store.backRouter=store.xieyiLink;
	uni.$tools.GoUrl("/pages/webview/webview");
}


const confirmPicker=(e:any)=>{
	console.log("确定选择:",e,Date_EE(e.value));
	pinfo.data.appointmenttime=Date_EE(e.value);
	show.value=false;
}
const cancelPicker=()=>{
	closePicker();
}


const choicetime=()=>{
	show.value=true;
}

const goselect=()=>{
	//先跳过去选择医院
	uni.$tools.GoUrl("/pages/selecthospital/selecthospital");
	//uni.$tools.GoUrl("/pages/guahao/guahao");
}


//读取数据
const readData=()=>{
	let paraData={
		userinfoid:userData.userinfo.id,
		studentidcard:userData.binduseridcard,
	}
	console.log("读取数据参数:",paraData);
	uni.$tools.Reqeust('/api/readSignHistory',paraData,'POST').then((res:any)=>{
			console.log('读取数据结果:',res);
			if (res.data.code == 200) {
				if(res.data.data!=null){
					pinfo.data.studentName=res.data.data.studentname;
					pinfo.data.jiaZhangPhone=store.phone;
				}else{
					pinfo.data.jiaZhangPhone=userData.userinfo.phone;
				}
			}else{
				//uni.$tools.Toast(res.data.msg);
			}
	})
}


//保存数据
const saveData=()=>{
	
	console.log("pinfo.data:",pinfo.data,!/\S/.test(pinfo.data.studentSex));
	
	if(!/\S/.test(pinfo.data.studentName) || pinfo.data.studentName===undefined){
		uni.$tools.Toast("请填写学生姓名");
		return;
	}
	if(!/\S/.test(pinfo.data.studentSex) || pinfo.data.studentSex===undefined){
		uni.$tools.Toast("请填写性别");
		return;
	}
	if(!/\S/.test(pinfo.data.className) || pinfo.data.className===undefined){
		uni.$tools.Toast("请填写班级");
		return;
	}
	if(!/\S/.test(pinfo.data.teacherName) || pinfo.data.teacherName===undefined){
		uni.$tools.Toast("请填写老师姓名");
		return;
	}
	if(!/\S/.test(pinfo.data.jiaZhangPhone) || pinfo.data.jiaZhangPhone===undefined){
		uni.$tools.Toast("请填写家长电话");
		return;
	}
	
	if(pinfo.data.problemArr.length<2){
		uni.$tools.Toast("至少选择2个问题");
		return;		
	}
	
	//测试
	//pinfo.data.appointmenttime="2024-08-25(星期六) 09:00至09:30";
	
	if(pinfo.data.appointmenttime==='' || pinfo.data.appointmenttime===undefined){
		uni.$tools.Toast("请选择预约时间");
		return;
	}
	
	if(pinfo.data.appointmentthospital==='' || pinfo.data.appointmenttime===''){
		uni.$tools.Toast("请选择体检站点和预约时间");
		return;
	}
	
	if(pinfo.data.patriarchsignimage==='' || pinfo.data.patriarchsignimage===undefined){
		uni.$tools.Toast("请家长签名");
		return;
	}
		
	if(pinfo.data.studentsignimage==='' || pinfo.data.studentsignimage===undefined){
		uni.$tools.Toast("请学生签名");
		return;
	}	
	
	
	if(xieyiChecked.value===false){
		uni.$tools.Toast("请勾选并同意服务协议");
		return;	
	}
	
	
	//订阅就诊提醒信息
	uni.requestSubscribeMessage({
	  tmplIds: ['qIexIbKYzoXSpxhO6RDApMbiPU0BB3jwsBoLqtVZZMY'],
	  success:res=>{ 
		  console.log("订阅结果:",res);
		  if(res.qIexIbKYzoXSpxhO6RDApMbiPU0BB3jwsBoLqtVZZMY==='accept'){
					let daynumber=pinfo.data.appointmenttime.split(" ")[0].replace("(星期六)","").replace("星期日","");
					let paraData={
							userinfoid:userData.userinfo.id,
							studentidcard:userData.binduseridcard,
							studentname:userData.bindusername,
							studentsex:pinfo.data.studentSex,
							studentclass:pinfo.data.className,
							teachername:pinfo.data.teacherName,
							teacherphone:pinfo.data.teacherPhone,
							patriarchphone:pinfo.data.jiaZhangPhone,
							studentphone:pinfo.data.studentPhone,
							problemlist:JSON.stringify(pinfo.data.problemArr), //这里要转换成数组字符 使用JSON.Strify
							appointmentthospital:pinfo.data.appointmentthospital, //体检医院
							appointmenttime:pinfo.data.appointmenttime, 
							daynumber:ChineseDate(daynumber), //需要转换成这种格式 例如：2019年10月1日，或：2019年10月1日 15:01
							appweek:pinfo.data.appweek,
							starttime:pinfo.data.starttime,
							endtime:pinfo.data.endtime,
							patriarchsignimage:pinfo.data.patriarchsignimage,
							studentsignimage:pinfo.data.studentsignimage,
							token:uni.getStorageSync("token")!=null?uni.getStorageSync("token"):null,
						}
						console.log("保存参数:",paraData);
						//return;
						uni.$tools.Reqeust('/api/saveSignHistory',paraData,'POST').then((res:any)=>{
								console.log('保存结果:',res);
								if (res.data.code == 200) {
									userData.appointment="";
									userData.pinfo={};
									uni.$tools.Toast("保存成功");
									setTimeout(()=>{
										uni.$tools.GoUrl("/pages/yuyue/yuyue");
									},1000);
								}else{
									uni.$tools.Toast(res.data.msg);
								}
						})  
		  }else{
				// uni.showModal({
				// 	title:'温馨提示',
				// 	content:'你已拒绝接收消息通知，是否点击前往设置',
				// 	showCancel:true,
				// 	success:mres=>{
				// 		if(mres.confirm){
				// 			uni.openSetting({
				// 			  success(res) {
				// 				//console.log(res.authSetting)
				// 			  }
				// 			});
				// 		}
				// 	}
			 //  })			  
		  } //if end
	  } //success end
	})

	
	
}

//let instance=getCurrentInstance();
//let context = uni.createCanvasContext('myCanvas', instance); // 'myCanvas' 是 canvas 组件的 canvas-id

//屏幕截图
//const screenShotPage=()=>{

		
		//有效
		/*
		  const sysinfo = uni.getSystemInfoSync();
		  context.width = sysinfo.windowWidth;
		  context.height = sysinfo.windowHeight;
		//context.setFillStyle('red')
		context.fillRect(0, 0, 300, 300);
		context.draw();
		//*/
		
		
		//*/
	  //   uni.createSelectorQuery().select('#screenShot').fields({ size: true, node: true }, res => {
			// console.log("返回区域值:",res);
			//   const width = res.width;
			//   const height = res.height;
			  
			//   const sysinfo = uni.getSystemInfoSync();
			//   context.width = sysinfo.windowWidth;
			//   context.height = sysinfo.windowHeight;
			  
			//   //context.fillRect(0, 350, 300, 300);
			//   //context.fill();
			//   context.draw(true,() => {
			// 	  setTimeout(()=>{
			// 			uni.canvasToTempFilePath({
			// 			  width:width,
			// 			  height:height,
			// 			  canvasId: 'myCanvas',
			// 			  success: (rct) => {
			// 				console.log("图片路径:",rct);
			// 				uni.saveImageToPhotosAlbum({ filePath: rct.tempFilePath, success: () => {
			// 				  uni.showToast({ title: '截图成功' });
			// 				} });
			// 			  },
			// 			  fail: () => {
			// 				uni.showToast({ title: '截图失败', icon: 'none' });
			// 			  }
			// 			});					  
			// 	  },5000);
			// });
	  //   }).exec();
//}




//获取系统信息
uni.getSystemInfo({
	success: function(res) {
		canvasw = res.windowWidth;
		canvash = res.windowHeight;
	},
})



let signtype=ref('jiazhang');  //jiazhang 家长签名 / student 学生签名
//let signImage=ref('');
let JiaZhangSignImage=ref(''); //家长签名
let StudentSignImage=ref('');  //学生签名
let isEnd=ref(false); // 是否签名

onLoad(()=>{
	_that = this
	//获得Canvas的上下文
	content.value = uni.createCanvasContext('firstCanvas',_that)
	//console.log(userData.pinfo==={},JSON.stringify(userData.pinfo)==='{}',userData.pinfo)
	
	//读取数据
	readData();
});

/*
weekstr = //2024-8-10(星期六) 08:40至09:00
*/
const getWeekNumber=(weekstr:string)=>{
	if(weekstr.indexOf("星期一")!=-1) return 1;
	if(weekstr.indexOf("星期二")!=-1) return 2;
	if(weekstr.indexOf("星期三")!=-1) return 3;
	if(weekstr.indexOf("星期四")!=-1) return 4;
	if(weekstr.indexOf("星期五")!=-1) return 5;
	if(weekstr.indexOf("星期六")!=-1) return 6; 
	if(weekstr.indexOf("星期日")!=-1) return 7;
	return -1;
}


const replaceStr=(inputString:string)=>{
	return inputString.replace("(星期一)","").replace("(星期二)","").replace("(星期三)","").replace("(星期四)","").replace("(星期五)","").replace("(星期六)","").replace("(星期日)","");
}

onShow(()=>{
	if(userData.userinfo===null || hasLogin===false){
		uni.$tools.Toast("会话失效请重新登录");
		setTimeout(()=>{
			uni.$tools.GoUrl('/pages/login/login',0);
		},1000);
		return;
	}
	
	if(userData.bindusername!=''){
		userData.pinfo.studentName=userData.bindusername;
		pinfo.data.studentName=userData.bindusername;
	}
	
	if(userData.appointment!=''){
		pinfo.data.appointmenttime=userData.appointment;  //2024-8-10(星期六) 08:40至09:00
		pinfo.data.daynumber=replaceStr(userData.appointment.split(" ")[0]);
		pinfo.data.appweek=getWeekNumber(userData.appointment)!=-1?getWeekNumber(userData.appointment):-1;
		pinfo.data.starttime=userData.appointment.split(" ")[1].replace("至",",").split(",")[0];
		pinfo.data.endtime=userData.appointment.split(" ")[1].replace("至",",").split(",")[1];
	}
	
	if(userData.appointmenthospital!=''){
		pinfo.data.appointmentthospital=userData.appointmenthospital;
	}
	
	
	if(!(JSON.stringify(userData.pinfo)==='{}')){
		if(!(JSON.stringify(userData.pinfo.problemArr)==='[]')){
			console.log("还原问题数据")
			if(userData.pinfo.problemArr!=null){
				pinfo.data.problemArr=userData.pinfo.problemArr;
				pinfo.data.problemArr.forEach(item=>{
					//消除已选中
					problemList[item.mainIndex].asks.forEach(item=>{
						item.s=false;
					})
					problemList[item.mainIndex].asks[item.subIndex].s=true;				
				})				
			}
		}
		//还原用户信息
		if(userData.pinfo.studentName!=''){
			pinfo.data.studentName=userData.pinfo.studentName;
		}
		if(userData.pinfo.studentSex!=''){
			pinfo.data.studentSex=userData.pinfo.studentSex;
		}
		if(userData.pinfo.className!=''){
			pinfo.data.className=userData.pinfo.className;
		}
		if(userData.pinfo.teacherName!=''){
			pinfo.data.teacherName=userData.pinfo.teacherName;
		}
		if(userData.pinfo.teacherPhone!=''){
			pinfo.data.teacherPhone=userData.pinfo.teacherPhone;
		}	
		if(userData.pinfo.studentPhone!=''){
			pinfo.data.studentPhone=userData.pinfo.studentPhone;
		}
		if(userData.pinfo.jiaZhangPhone!=''){
			pinfo.data.jiaZhangPhone=userData.pinfo.jiaZhangPhone;
		}		
		
		
		//还原签名
		if(userData.pinfo.patriarchsignimage!=''){
			JiaZhangSignImage.value=userData.pinfo.patriarchsignimage;
			pinfo.data.patriarchsignimage=userData.pinfo.patriarchsignimage;
		}
		if(userData.pinfo.studentsignimage!=''){
			StudentSignImage.value=userData.pinfo.studentsignimage;
			pinfo.data.studentsignimage=userData.pinfo.studentsignimage;
		}
	}
	
	//保存一次数据
	userData.pinfo=pinfo.data;
})

const hideShow=()=>{
		console.log('333')
		pop.value.hide();
}

const showSign=(stype:string)=>{
	signtype.value=stype;
	console.log("什么签名",signtype.value)
	pop.value.show();
}

const BASE_URL=import.meta.env.VITE_API_URL; 
const overSign=()=>{
	if (isEnd.value) {
		uni.canvasToTempFilePath({
			canvasId: 'firstCanvas',
			success:(res)=> {
				//打印图片路径
				console.log(res.tempFilePath)
				console.log('完成签名',uni.getStorageSync("token"))
				if(signtype.value==='jiazhang'){
					JiaZhangSignImage.value = res.tempFilePath;
					console.log("家长图片路径",JiaZhangSignImage.value);
				}
				if(signtype.value==='student'){
					StudentSignImage.value = res.tempFilePath;
					console.log("学生图片路径",StudentSignImage.value);
				}
				
				//执行绘画操作
				hideShow();
				clearClick();

				
				uni.uploadFile({
						url: BASE_URL+'/common/uploadSignImageFile/'+signtype.value, //仅为示例，非真实的接口地址
						header:{
							'Authorization':uni.getStorageSync("token")!=''?uni.getStorageSync("token"):null,
						},
						filePath:signtype.value==='jiazhang'?JiaZhangSignImage.value:StudentSignImage.value,
						name: 'file',
						formData: {},
						success: (r) => {
							console.log("文件上传结果",r.data);
							let json=JSON.parse(r.data);
							if(json.code===200){
								if(json.uploadImageUrl!=''){
									if(signtype.value==='jiazhang'){
										pinfo.data.patriarchsignimage=json.uploadImageUrl;
									}
									if(signtype.value==='student'){
										pinfo.data.studentsignimage=json.uploadImageUrl;
									}
									console.log("pinfo",pinfo);
									userData.pinfo=pinfo.data;
								}
							}
						}
				});
			},
			
		})
	} else {
		uni.showToast({
			title: '请先完成签名',
			icon: "none",
			duration: 1500,
			mask: true
		})
	}

}


// 画布的触摸移动开始手势响应
const start=(event:any)=>{
	//console.log(event)
	//console.log("触摸开始" + event.changedTouches[0].x)
	//console.log("触摸开始" + event.changedTouches[0].y)
	//获取触摸开始的 x,y
	let point = {
		x: event.changedTouches[0].x,
		y: event.changedTouches[0].y
	}
	// console.log(point)
	touchs.push(point);
}


// 画布的触摸移动手势响应
const move=(e:any)=>{
	let point = {
		x: e.touches[0].x,
		y: e.touches[0].y
	}
	// console.log(point)
	touchs.push(point)
	if (touchs.length >= 2) {
		draw(touchs);
	}
}

// 画布的触摸移动结束手势响应
const end=(e:any)=>{
	// 设置为已经签名
	isEnd.value = true;
	console.log('end')
	// 清空轨迹数组
	touchs=[];
	// for (let i = 0; i < touchs.length; i++) {
	// 	touchs.pop()
	// }
}
// 画布的触摸取消响应
const cancel=(e)=>{};

// 画布的长按手势响应
const tap=(e)=>{};

//画布触摸错误
const error=()=>{};


//绘制
const draw=(touchs:any)=>{
	let point1 = touchs[0]
	let point2 = touchs[1]
	touchs.shift()
	//设置线的颜色
	content.value.setStrokeStyle("#000")
	//设置线的宽度
	content.value.setLineWidth(5)
	//设置线两端端点样式更加圆润
	content.value.setLineCap('round')
	//设置两条线连接处更加圆润
	content.value.setLineJoin('round')
	content.value.moveTo(point1.x, point1.y)
	content.value.lineTo(point2.x, point2.y)
	content.value.stroke()
	content.value.draw(true)
}

//清除操作
const clearClick=()=>{
	// 设置为未签名
	isEnd.value = false
	//清除画布
	content.value.clearRect(0, 0, canvasw, canvash)
	content.value.draw(true)
}


let pinfo=reactive({
	data:{
		studentName:'',
		studentSex:'',
		className:'',
		teacherName:'',
		teacherPhone:'',
		jiaZhangPhone:'', //家长	
		studentPhone:'',
		problemArr:[], //问题集合
		appointmentthospital:'', //体检医院
		appointmenttime:'', //预约时间 2024年08月02日 21:00
		daynumber:'', //日期 2024-08-11
		appweek:-1,
		starttime:'',
		endtime:'',
		patriarchsignimage:'', //家长签名图片
		studentsignimage:'',   //学生签名图片
	}
});

let patitle=ref('');
let paindex=ref(-1);
let problemList=reactive([
	{
		title:'1.请问您和您的家长/监护人是否已经了解心理健康面谈筛查的必要性？', //问题
		asks:[
			{t:'A.非常了解',s:false},
			{t:'B.一般了解',s:false},
			{t:'C.不了解',s:false}
		],   //答案
	},
	{
		title:'2.请问您和您的家长/监护人是否愿意到医院体检中心配合心理医生面谈筛查咨询？', //问题
		asks:[
			{t:'A.非常愿意',s:false},
			{t:'B.一般愿意（考虑）',s:false},
			{t:'C.不愿意',s:false}
		],   //答案
	}
]);
let Result=reactive({data:[]});
const selectASK=(title:string,mainIndex:number,subIndex:number)=>{
	let obj:any={};
	obj.mainIndex=mainIndex;
	obj.subIndex=subIndex;
	obj.title=title;
	obj.ask=problemList[mainIndex].asks[subIndex].t;
	
	//删除当前标题
	for(let i=0;i<Result.data.length;i++){
		if(Result.data[i].title===title){
			Result.data.splice(i,1);//删除
		}
	}
	
	let index=Result.data.findIndex(item=>item.title===title && item.ask===obj.ask);
	console.log("是否存在index",index);
	if(index===-1){
		Result.data.push(obj);
		//消除已选中
		problemList[mainIndex].asks.forEach(item=>{
			item.s=false;
		})
		problemList[mainIndex].asks[subIndex].s=true;
	}
	//console.log(Result.data);
	
	pinfo.data.problemArr=Result.data;
	console.log("pinfo",pinfo);
	userData.pinfo=pinfo.data;
}
const customstyle=reactive({
	'width':'180rpx',
	'height':'60rpx',
	'padding':'0px',
	'paddingLeft':'10rpx !important',
	'margin':'0px'
});
const customstyle120=reactive({
	'width':'120rpx',
	'height':'60rpx',
	'padding':'0px',
	'paddingLeft':'10rpx !important',
	'margin':'0px'
});
const customstyle200=reactive({
	'width':'250rpx',
	'height':'60rpx',
	'padding':'0px',
	'paddingLeft':'10rpx !important',
	'margin':'0px'
});







// 调用此方法来截图当前页面
//const saveCanvas = () => {
	//const ctx = uni.createCanvasContext('myCanvas', this);
	//console.log("ctx",ctx); 
	 //  ctx.drawImage(0,0,0, uni.getSystemInfoSync().windowWidth,uni.getSystemInfoSync().windowHeight, 0, 0, uni.getSystemInfoSync().windowWidth,uni.getSystemInfoSync().windowHeight);
	 //  try {
		// uni.canvasToTempFilePath({
		//   canvasId: 'myCanvas',
		//   success: (res) => {
		// 	console.log('截屏保存成功:', res);
		// 	// 这里可以执行保存图片到相册或其他操作
		// 	uni.saveImageToPhotosAlbum({
		// 			filePath: res.tempFilePath,
		// 			success: function () {
		// 				console.log('save success');
		// 			}
		// 	});
		//   },
		//   fail: (err) => {
		// 	console.error('截屏失败:', err);
		//   }
		// });
	 //  } catch (error) {
		// console.error('截屏失败:', error);
	 //  }
//};
</script>
<style>
page{ padding-bottom:200rpx; }
</style>
<style lang='scss' scoped>
	@import "word.scss";
	.ts {
		color: #FF485D;
		font-size: 30upx;
		height: 100upx;
		line-height: 100upx;
		padding-left: 20upx;
	}
	
	canvas {
		background-color: #f2f2f2;
		width: 100%;
		height:20vh;
		/* margin: 0 25upx; */
		/* height: calc(100vh - 140upx); */
	}
	.contents {
		padding-top: 20upx;
		padding-bottom: 100upx;
		box-sizing: border-box;
	}
	
	#signatureImg {
		background-color: #EEEEEE;
	}
	.caozuo1 {
		display: flex;
		height: 0;
		height: constant(safe-area-inset-bottom);  
		height: env(safe-area-inset-bottom);
		width: 750upx;
		position: fixed;
		left: 0;
		bottom: 0;
		background-color: #0599D7;
	
	}
	.caozuo {
		display: flex;
		height: 100rpx;
		width: 100%;
		margin-top:20rpx;
		font-size: 28rpx;
		
	}
	.caozuo view {
		width: 40%;
		text-align: center;
		height: 80rpx;
		line-height: 80rpx;
		color: #FFFFFF;
		margin-left:5%;
		border-radius: 40rpx;
	}
	.caozuo view:last-child {
		width: 40%;
		text-align: center;
		height: 80rpx;
		line-height: 80rpx;
		color: #FFFFFF;
		margin-left:10%;
	}
	
	.caozuo view:active {
		background-color: #CCCCCC;
		color: #333333;
	}
	
	.chongqian {
		background-color: #FF8F58;
	}
	
	.over {
		background-color: #0599D7;
	}
</style>